<?php
//include database connection
include 'lib/database.php';

//select all data
$con = Database::connect();
$query = "SELECT id_aspirante,nombres, apellidos, email, carrera, cum FROM tbl_aspirante ORDER BY cum desc";
$stmt = $con->prepare( $query );
$stmt->execute();

//this is how to get number of rows returned
$num = $stmt->rowCount();

if($num>0){ //check if more than 0 record found

    echo "<table id='tfhover' class='tftable' border='1'>";//start table
    
        //creating our table heading
        echo "<tr>";
            echo "<th>Nombres</th>";
            echo "<th>Apellidos</th>";
            echo "<th>Email</th>";
            echo "<th>Carrera</th>";
            echo "<th>Cum</th>";
            echo "<th style='text-align:center;'>Action</th>";
        echo "</tr>";
        
        //retrieve our table contents
        //fetch() is faster than fetchAll()
        
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            //exraer row
            //esto convertira $row['nombres'] a
            //solo $nombres 
            extract($row);
            
            //creating new table row per record
            echo "<tr>";
                echo "<td>{$nombres}</td>";
                echo "<td>{$apellidos}</td>";
                echo "<td>{$email}</td>";
                echo "<td>{$carrera}</td>";
                echo "<td>{$cum}</td>";
                echo "<td style='text-align:center;'>";
					// add the record id here
					echo "<div class='userId'>{$id_aspirante}</div>";
					
                    //we will use this links on next part of this post
                    echo "<div class='editBtn customBtn'>Edit</div>";
					
                    //we will use this links on next part of this post
                    echo "<div class='deleteBtn customBtn'>Delete</div>";
                echo "</td>";
            echo "</tr>";
        }
        
    echo "</table>";//end table
    
}

// tell the user if no records found
else{
    echo "<div class='noneFound'>No Se encontraron Registros</div>";
}

?>